<!-- 报到人工审核 -->
<template>
    <div class="edu-page-warp">
        <condition-card
            @reset="reset"
            @search="onSubmit"
            label-width="110px"
            label-position="right"
        >
            <el-row>
                <el-col :span="8">
                    <el-form-item label="年级">
                        <grade-select
                            v-model="queryForm.grade"
                            :show-all="false"
                            @change="currentDptId === '1' ? changeFaculty() : ''"
                        ></grade-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学院">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.faculty"
                            :data="options.faculty"
                            @change="changeFaculty"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="专业">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.profession"
                            :data="options.profession"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养层次">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.trainingLevel"
                            :data="options.trainingLevel"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养类别">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.trainingCategory"
                            :data="options.trainingCategory"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学位类型">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.degreeType"
                            :data="options.degreeType"
                            @change="currentDptId !== '1' ? changeFaculty() : ''"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学习形式">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.formLearning"
                            :data="options.formLearning"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="迎新任务">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.isFinishTask"
                            :data="options.isFinishTask"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="是否国际学生">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.isOverseas"
                            :data="options.isOverseas"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="缴费状态">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.paymentStatus"
                            :data="options.paymentStatus"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="通道类型">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.isSpecialApplication"
                            :data="options.isSpecialApplication"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="报到状态">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.registerStatus"
                            :data="options.registerStatus"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8" v-if="currentDptId !== '1'">
                    <el-form-item label="入学季节">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.enrolSeason"
                            :data="options.enrolSeason"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="在校状态">
                        <DictSelect
                            labelAll="请选择"
                            v-model="queryForm.leaveSchool"
                            :data="options.leaveSchool"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="人像对比(%)">
                        <el-row type="flex">
                            <el-col>
                                <el-input
                                    type="text"
                                    v-model="similar.minSimilar"
                                    size="mini"
                                    placeholder="输入最小值"
                                ></el-input>
                            </el-col>
                            <div class="text-center" style="padding: 0 8px;">至</div>
                            <el-col>
                                <el-input
                                    type="text"
                                    v-model="similar.maxSimilar"
                                    size="mini"
                                    placeholder="输入最大值"
                                ></el-input>
                            </el-col>
                        </el-row>
                    </el-form-item>
                </el-col>
            </el-row>
        </condition-card>
        <el-card shadow="never">
            <h2 class="edu-page-title">学生状态列表</h2>
            <el-row type="flex" class="mb-8px">
                <el-col>
                    <KeywordInput v-model="queryForm.name" @enter="filter" placeholder="学号或姓名搜索"></KeywordInput>
                </el-col>
                <el-col class="text-right">
                    <el-dropdown trigger="click" @command="handleCommand">
                        <el-button>
                            导出
                            <i class="el-icon-arrow-down el-icon--right"></i>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item command="exportExcel">导出学生状态列表</el-dropdown-item>
                            <el-dropdown-item command="exportDBF">导出学生状态DBF</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                    <!-- <el-button @click="exportToExcel" size="mini">导出</el-button> -->
                </el-col>
            </el-row>
            <edu-table
                :order="false"
                :data="studentStatusList.data"
                :total="studentStatusList.total"
                @page-change="pageChange"
                @selection-change="handleSelectionChange"
            >
                <el-table-column label="学号" prop="studentId"></el-table-column>
                <el-table-column label="姓名">
                    <template slot-scope="scope">{{scope.row.name}}</template>
                </el-table-column>
                <el-table-column label="学院" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.facultyI18n}}</template>
                </el-table-column>
                <el-table-column label="专业" show-overflow-tooltip>
                    <template slot-scope="scope">{{scope.row.professionI18n}}</template>
                </el-table-column>
                <el-table-column label="迎新任务">
                    <template slot-scope="scope">{{scope.row.isFinishTask | getIsFinishTask}}</template>
                </el-table-column>
                <el-table-column label="培养层次">
                    <template slot-scope="scope">{{scope.row.trainingLevelI18n}}</template>
                </el-table-column>
                <el-table-column label="培养类别">
                    <template slot-scope="scope">{{scope.row.trainingCategoryI18n}}</template>
                </el-table-column>
                <el-table-column label="学位类型">
                    <template slot-scope="scope">{{scope.row.degreeTypeI18n}}</template>
                </el-table-column>
                <el-table-column label="学习形式">
                    <template slot-scope="scope">{{scope.row.formLearningI18n}}</template>
                </el-table-column>
                <el-table-column label="缴费状态">
                    <template slot-scope="scope">{{scope.row.paymentStatus | getPaymentStatus}}</template>
                </el-table-column>
                <el-table-column label="人像对比">
                    <template slot-scope="scope">{{scope.row.similar | turnPer}}</template>
                </el-table-column>
                <el-table-column label="通道类型">
                    <template
                        slot-scope="scope"
                    >{{scope.row.isSpecialApplication | getIsSpecialApplication}}</template>
                </el-table-column>
                <el-table-column label="报到状态">
                    <template slot-scope="scope">
                        <div v-if="scope.row.registerStatus">
                            <el-tag
                                :type="scope.row.registerStatus === '1' ? 'success' : 'info'"
                            >{{ scope.row.registerStatus | getRegister}}</el-tag>
                        </div>
                    </template>
                </el-table-column>
            </edu-table>
        </el-card>
    </div>
</template>
<script>
import studentCheckApi from "common/src/api/welcomeService/studentCheck";
import UTILS from "common/src/utils/utils";
import { queryDic } from "common/src/api/dictionary";
import { getImageData } from "common/src/api/teacherinfo";
import { findFaculty } from "common/src/api/faculty";
export default {
    name: "ManualReview",
    data() {
        return {
            similar: {
                minSimilar: "",
                maxSimilar: ""
            },
            queryForm: {
                grade: "", //年级
                faculty: "", //学院
                profession: "", //专业
                trainingLevel: "", //培养层次
                trainingCategory: "", // 培养类别
                degreeType: "", // 学位类型
                formLearning: "", // 学习形式
                isFinishTask: "", // 迎新任务
                isOverseas: "", //是否留学生
                paymentStatus: "", //缴费状态
                isSpecialApplication: "", //绿色通道
                registerStatus: "", //报到状态
                enrolSeason: "", // 入学季节
                leaveSchool: "", // 在校状态
                minSimilar: "",
                maxSimilar: "",
                name: "", //学号或姓名
                pageNum_: 1,
                pageSize_: 20
            },
            options: {
                faculty: [],
                profession: [],
                trainingLevel: [],
                trainingCategory: [],
                degreeType: [],
                formLearning: [],
                isFinishTask: [
                    {
                        label: "未完成",
                        value: "0"
                    },
                    {
                        label: "已完成",
                        value: "1"
                    }
                ],
                isOverseas: [],
                paymentStatus: [
                    {
                        label: "未缴费",
                        value: "0"
                    },
                    {
                        label: "已缴费",
                        value: "1"
                    },
                    {
                        label: "缓缴费",
                        value: "2"
                    }
                ],
                registerStatus: [
                    {
                        label: "未报到",
                        value: "0"
                    },
                    {
                        label: "已报到",
                        value: "1"
                    }
                ],
                isSpecialApplication: [
                    {
                        label: "正常通道",
                        value: "1"
                    },
                    {
                        label: "绿色通道",
                        value: "2"
                    },
                    {
                        label: "人工通道",
                        value: "3"
                    }
                ],
                enrolSeason: [],
                leaveSchool: []
            },
            studentStatusList: {
                data: [],
                total: 0
            },
            selectedItems: [],
            currentDptId: ""
        };
    },
    created() {
        if (this.mockUser) {
            this.currentDptId = this.mockUser.currentManageDptId;
        } else if (this.currentUser) {
            this.currentDptId = this.currentUser.currentManageDptId;
        }
        this.init();
        this.onSubmit();
    },
    methods: {
        // 初始化获取筛选条件字典值
        init() {
            //year
            let year = new Date().getFullYear();
            this.queryForm.grade = year;
            let data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: [
                    "X_YX",
                    "X_PYCC",
                    "X_PYLB",
                    "X_XWLX",
                    "X_XXXS",
                    "isAborad",
                    "X_RXJJ",
                    "L_LXZT"
                ]
            };
            queryDic(data)
                .then(res => {
                    if (res.code == 200) {
                        UTILS.fillSelect(
                            {
                                faculty: "X_YX",
                                trainingLevel: "X_PYCC",
                                trainingCategory: "X_PYLB",
                                degreeType: "X_XWLX",
                                formLearning: "X_XXXS",
                                isOverseas: "isAborad",
                                enrolSeason: "X_RXJJ",
                                leaveSchool: "L_LXZT"
                            },
                            res.data,
                            this.options
                        );
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //学院改变获取专业
        changeFaculty(val) {
            this.options.profession = [];
            this.queryForm.profession = "";
            let facultys,degreeType;
            facultys = this.queryForm.faculty ? [this.queryForm.faculty] : [];
            degreeType = this.queryForm.degreeType ? [this.queryForm.degreeType] : [];
            let data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: facultys,
                    specilaCode: "XY2ZY",
                    facultys: facultys,
                    grade: this.queryForm.grade,
                    degreeType: degreeType
                }
            };
            queryDic(data)
                .then(res => {
                    if (res.code == 200)
                        UTILS.fillSelect(
                            {
                                profession: "G_ZY"
                            },
                            res.data,
                            this.options
                        );
                })
                .catch(error => {
                    console.log(error);
                });
        },
        // 导出excel、dbf
        exportToExcel(type) {
            let queryForm = _.cloneDeep(this.queryForm);
            if (type && type === "1") {
                queryForm.exportType = "";
            } else if (type && type === "2") {
                queryForm.exportType = "dbfType";
            }
            if (this.selectedItems.length) {
                let ids = this.selectedItems.map(item => {
                    return item.studentId;
                });
                queryForm.ids = ids;
            }
            studentCheckApi.findNewStuInfoReportListExport(queryForm);
        },
        // 过滤条件重置
        reset() {
            // 重置人像对比
            this.similar = {
                minSimilar: "",
                maxSimilar: ""
            };
            let queryForm = this.queryForm;
            for (var key in queryForm) {
                if (key.includes("grade")) {
                    queryForm[key] = new Date().getFullYear();
                } else if (key.includes("pageNum_")) {
                    queryForm[key] = 1;
                } else if (key.includes("pageSize_")) {
                    queryForm[key] = 20;
                } else if (!key.includes("name")) {
                    queryForm[key] = "";
                }
            }
            this.options.profession = [];
            this.getStudentList();
        },
        getStudentList(showDialog = false) {
            // 删除ids
            if (this.queryForm.hasOwnProperty("ids")) {
                delete this.queryForm["ids"];
            }
            studentCheckApi
                .findNewStuInfoReportList(this.queryForm)
                .then(response => {
                    if (response.code == 200) {
                        this.studentStatusList = {
                            data: response.data.list,
                            total: response.data.total_
                        };
                    } else {
                        throw "查询失败";
                    }
                })
                .catch(error => {
                    this.$message({
                        type: "error",
                        message: "查询失败"
                    });
                });
        },
        onSubmit() {
            this.queryForm.minSimilar = this.similar.minSimilar.trim();
            this.queryForm.maxSimilar = this.similar.maxSimilar.trim();
            let numberReg = /^[0-9]+\.?[0-9]*$/;
            if (
                this.queryForm.minSimilar != "" &&
                !numberReg.test(this.queryForm.minSimilar)
            ) {
                this.$message({
                    type: "error",
                    message: "人像比对最小值输入有误"
                });
                return;
            }
            if (
                this.queryForm.maxSimilar != "" &&
                !numberReg.test(this.queryForm.maxSimilar)
            ) {
                this.$message({
                    type: "error",
                    message: "人像比对最大值输入有误"
                });
                return;
            }
            this.queryForm.maxSimilar =
                this.queryForm.maxSimilar &&
                (this.queryForm.maxSimilar / 100).toFixed(2);
            this.queryForm.minSimilar =
                this.queryForm.minSimilar &&
                (this.queryForm.minSimilar / 100).toFixed(2);
            this.queryForm.pageNum_ = 1;
            this.getStudentList(true);
        },
        pageChange(val) {
            this.queryForm.pageNum_ = val.pageNum;
            this.queryForm.pageSize_ = val.pageSize;
            this.getStudentList();
        },
        handleSelectionChange(val) {
            this.selectedItems = val;
        },
        filter() {
            this.onSubmit();
        },
        //根据val返回缴费文本
        getPayText(val) {
            let result = this.options.paymentStatus.find(
                option => option.value == val
            );
            return result ? result.label : "";
        },
        //根据val返回绿色通道文本
        getSpecialApplicationText(val) {
            let option = this.options.specialApplication.find(
                option => option.value == val
            );
            return option ? option.label : "";
        },
        //根据val返回迎新任务状态
        getTaskStatus(val) {
            return val == 1 ? "已完成" : "未完成";
        },
        //对比值转化
        convertRadio(val) {
            if (val != null) {
                val = parseFloat(val);
                return val.toFixed(2);
            } else {
                return val;
            }
        },
        // 导出
        handleCommand(command) {
            if (command === "exportExcel") {
                this.exportToExcel("1");
            } else if (command === "exportDBF") {
                this.exportToExcel("2");
            }
        }
    },
    computed: {
        currentUser() {
            if (this.$store.state.session.user) {
                return this.$store.state.session.user;
            }
            return JSON.parse(localStorage.getItem("user"));
        },
        mockUser() {
            if (this.$store.state.session.mockUser) {
                return this.$store.state.session.mockUser;
            }
            let sessiondata = JSON.parse(localStorage.getItem("sessiondata"));
            if (sessiondata && sessiondata.mockUser) {
                return sessiondata.mockUser;
            }
        }
    },
    filters: {
        getIsFinishTask(val) {
            let task = "";
            switch (val) {
                case "0":
                    task = "未完成";
                    break;
                case "1":
                    task = "已完成";
                    break;
                default:
                    task;
            }
            return task;
        },
        getPaymentStatus(val) {
            let status = "";
            switch (val) {
                case "0":
                    status = "未缴费";
                    break;
                case "1":
                    status = "已缴费";
                    break;
                case "2":
                    status = "缓缴费";
                    break;
                default:
                    status;
            }
            return status;
        },
        getIsSpecialApplication(val) {
            let channel = "";
            switch (val) {
                case "1":
                    channel = "正常通道";
                    break;
                case "2":
                    channel = "绿色通道";
                    break;
                case "3":
                    channel = "人工通道";
                    break;
                default:
                    channel;
            }
            return channel;
        },
        getRegister(val) {
            let register = "";
            switch (val) {
                case "0":
                    register = "未报到";
                    break;
                case "1":
                    register = "已报到";
                    break;
                default:
                    register;
            }
            return register;
        },
        turnPer(val) {
            let per = (val * 100).toFixed(2) + "%";
            return per;
        }
    }
};
</script>
<style scoped>
.demo-table-expand .el-form-item__label {
    color: red !important;
}
.demo-table-expand .el-form-item {
    margin: 0;
}
.demo-table-expand .el-form-item .img1 {
    width: 90px;
    height: 120px;
    border: 1px solid #d2d4d6;
    margin-top: 12px;
}
.demo-table-expand .el-form-item .img2 {
    width: 160px;
    height: 120px;
    border: 1px solid #d2d4d6;
    margin-top: 12px;
}
</style>
